package game.Screens;

import game.ActionListener;
import game.Game;
import game.GameHud;
import game.LevelManager;
import game.Actors.Actor;
import game.Config.Config;
import game.Config.Config.GameInput;
import game.Config.Storage;
import game.Config.TowerConfig;
import game.Config.TowerInfo;
import game.Menus.HorizontalMenu;
import game.Menus.TowerMenuItem;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;

/**
 * This screen represent the tower store. The screen where the player can build new towers.
 * @author Sebastian Isheden and Victor Beer
 *
 */
public class TowerScreen extends Screen{

	HorizontalMenu menu = new HorizontalMenu(0,Config.TOWER_MENU_GAP);
	@Override
	/**
	 * Initializes the screen.
	 */
	public void begin() {
		for(final TowerInfo info : TowerConfig.basicTowers){
			menu.addItem(new TowerMenuItem(info,new ActionListener(){
				@Override
				public void action() {
					if(Storage.getPlayer().buildTower(info))
						quit();
				}
			}));
		}
	}

	@Override
	public void end() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(GameContainer gc, int delta) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * Draws the screen.
	 */
	@Override
	public void draw(Graphics graphic) {
		LevelManager.drawCurrentLevel(graphic);
		Actor.drawAllActors();
		
		menu.draw(Config.TOWER_MENU_POSITION.copy(), graphic);
		GameHud.drawHud(graphic);
	}

	/**
	 * Check all the new input presses.
	 */
	@Override
	public void inputPressed(GameInput input) {
		if(input == GameInput.LEFT){
			menu.left();
		}
		if(input == GameInput.RIGHT){
			menu.right();
		}
		if(input == GameInput.ACTION){
			menu.press();
		}
		if(input == GameInput.BACK){
			quit();
		}
		
	}

	@Override
	public void inputDown(GameInput input) {
		// TODO Auto-generated method stub
		
	}

	private void quit(){
		Game.screenStack.pop();
	}
}
